package com.lemon.smartsafetynew.util.common;

import android.animation.ObjectAnimator;
import android.view.View;

/**
 * Created by Andrew on 2017/10/19.
 */

public class AnimationUtils {

    /**
     * 关闭 popupWindow 时的动画  Y轴
     *
     * @param view     mView
     * @param duration 动画执行时长
     * @param next     平移量
     */
    public static void closeAnimation(View view, int duration, int next) {
        ObjectAnimator anim = ObjectAnimator.ofFloat(view, "translationY", 0f, next);
        anim.setDuration(duration);
        anim.start();
    }

    /**
     * 启动动画  Y轴
     *
     * @param view     view
     * @param duration 执行时长
     * @param distance 执行的轨迹数组
     */
    public static void startAnimation(View view, int duration, float[] distance) {
        ObjectAnimator anim = ObjectAnimator.ofFloat(view, "translationY", distance);
        anim.setDuration(duration);
        anim.start();
    }

    /**
     * 开始启动角度
     *
     * @param view     view
     * @param duration 执行时长
     * @param rotation 执行的角度数组
     */
    public static void startRotationAnimation(View view, int duration, float[] rotation) {
        ObjectAnimator anim = ObjectAnimator.ofFloat(view, "rotation", rotation);
        anim.setDuration(duration);
        anim.start();
    }

    /**
     * 关闭回转角度
     *
     * @param view     view
     * @param duration 执行时长
     * @param rotation 执行的角度数组
     */
    public static void closeRotationAnimation(View view, int duration, float[] rotation) {
        ObjectAnimator anim = ObjectAnimator.ofFloat(view, "rotation", rotation);
        anim.setDuration(duration);
        anim.start();
    }
}
